<?
#####################################################
#  COPYRIGHT NOTICE
#####################################################
# In the following statements, the term "this 
# program" refers to all files associated with the
# execution and distribution of Adtrackz.
#
# This Program is Copyright 2004 Jonah Klimack.
# All Rights Reserved. 
#
# Selling the code for this program, modifying 
# and/or redistributing the code for this program
# in part or in whole over the Internet or in any 
# other medium is expressly forbidden. Violators
# will be prosecuted to the fullest extent of the law
# Copyright and header information may not be
# modified.
#
# This program is distributed "as is" and without 
# warranty of any kind, either express or implied.
# In no event shall the liability of Jonah Klimack 
# for any damages, losses and/or causes of 
# action exceed the total amount paid by the 
# user for this software.		
#####################################################
# DO NOT MODIFY ANYTHING IN THIS FILE
#####################################################


require "header.php";

?>

<p class="small" align="left">
Campaigns > View Errors
</p>

<p class="heading">
AdTrackzGold Error Messages
</p>

<p>
Check your error messages to see if there are any problems with your campaigns. Upon error, all traffic gets
redirected to your default url: 
<?
$url = mysql_fetch_row(mysql_query("select default_url from adtrackz_login"));
echo "<a href=$url[0] target=_new>$url[0]</a>. "
?>
 You can change your default url in the profile section of the misc. menu.
</p>

<?
if ($delete)
	mysql_query("delete from adtrackz_alerts");

if($from && !preg_match("/\b\d+\b/",$from))
{
	error("Starting from # must be an integer value.");
	$from = 0;
}
elseif (!$from)
	$from = 0;
else
	$from -= 1;
if($display_limit && !preg_match("/\b\d+\b/",$display_limit))
{
	error("Number of rows must be an integer value.");	
	$display_limit = 20;
}
if (!$display_limit)
	$display_limit = 20;

$alerts = mysql_query("select * from adtrackz_alerts order by timest limit $from, $display_limit");
$from += 1;
?>

<form action="alerts.php" method="post">
<center>
<table width=90%>
<tr>
	<td>
		<input type="submit" name="submit_display" value="Show:"  >
		<input type="text" name=display_limit  size=3 maxlength=3 value=<?=$display_limit?>> rows 
		starting from alert #<input type="text" name=from  size=3 maxlength=10 value=<?=$from?>>
	</td>
	<td align=right>
		<a href="alerts.php?delete=yes">Delete all error messages...</a>
	</td>
</tr>
</table>
<table width=90%>
<tr>
	<td>
	<?
	$total_alerts = mysql_num_rows(mysql_query("select * from adtrackz_alerts"));
	//break it down into pages
	$pages = $total_alerts / $display_limit;
	$remainder = $total_alerts % $display_limit;
	for($i=1;$i<=$pages;$i++)
	{
		if ($i == 1)
		{
			$page_start = $i;
			$page_end = $i*$display_limit;	
			echo "<a href=alerts.php?from=$page_start&display_limit=$display_limit&cID=$cID>$page_start - $page_end</a> | ";	
		}
		elseif ($i < $pages)
		{
			$page_start = (($i*$display_limit) - $display_limit) + 1;
			$page_end = $i*$display_limit;	
			echo "<a href=alerts.php?from=$page_start&display_limit=$display_limit&cID=$cID>$page_start - $page_end</a> | ";	
		}
		elseif ($i == $pages && !$remainder)
		{
			$page_start = (($i*$display_limit) - $display_limit) + 1;
			$page_end = $i*$display_limit;	
			echo "<a href=alerts.php?from=$page_start&display_limit=$display_limit&cID=$cID>$page_start - $page_end</a>";	
		}
	}
	if($remainder)
	{
		$page_start = $page_end + 1;
		$page_end = $page_end + $remainder;
		echo "<a href=alerts.php?from=$page_start&display_limit=$display_limit&cID=$cID>$page_start - $page_end</a>";		
	}
	?>		
	</td>
</tr>
</table>
	<br><br>
</center>

<table width="580" border="1" cellspacing="0" cellpadding="5" align="center" bordercolor="#e0e0e0">
<tr>
	<td class="tbhead1">Campaign</td>
	<td class="tbhead1">Sub</td>
	<td class="tbhead1">Date</td>
	<td class="tbhead1">Referring Url</td>
	<td class="tbhead1">Error Message</td>
</tr>
<?
if (!mysql_num_rows($alerts))
	echo "<tr><td colspan=8>There are no alerts to display.</td></tr></table>";
else
{
	for($i=0;$i<mysql_num_rows($alerts);$i++)
	{
		$alert = mysql_fetch_row($alerts);
		if (!$alert[2])
			$alert[2] = "-";
		if (!$alert[1])
			$alert[1] = "-";
print <<<END
<tr>
	<td class="tb1">$alert[1]</td>
	<td class="tb1">$alert[2]</td>
	<td class="tb1">$alert[3]</td>
	<td class="tb1">$alert[4]</td>
	<td class="tb1">$alert[5]</td>
</tr>
END;
	}
}
?>

</table>
</form>
<br>


<?
require "footer.php";

?>